Kameleon-Plus  0.3.2
Kameleon.h
Go to the documentation of this file.
1 /***
2  David Berrios
3 
4 
5  Header file for derived variable functionality. Just include this file
6  and link to the interplation library. Include derived_compatibility.h if
7  you want to use the C interface instead.
8  **/
9 
10 #ifndef KAMELEON_H
11 #define KAMELEON_H
12 
40 #include <map>
41 #include <set>
42 #include <string>
43 #include <vector>
44 #include <boost/unordered_map.hpp>
45 #include <boost/array.hpp>
46 #include <boost/lexical_cast.hpp>
47 #include <boost/format.hpp>
48 #include "Interpolator.h"
49 #include "Model.h"
50 #include "GeneralFileReader.h"
51 #include "TimeInterpolator.h"
52 #include "Constants.h"
53 #include "cxform.h"
54 #include <iostream>
55 #include "CCMCTime.h"
56 #include "Tracer.h"
57 
58 
59 //cdf constants
60 #define EPOCH3_STRING_LEN 24
61 
62 
63 
64 
69 namespace ccmc
70 {
71 
72  extern "C" double parseEPOCH3(char epString[EPOCH3_STRING_LEN+1]);
73  extern "C" void encodeEPOCH3(double epoch, char epString[EPOCH3_STRING_LEN+1]);
74  extern "C" void EPOCHbreakdown(
75  double epoch,
76  long *year,
77  long *month,
78  long *day,
79  long *hour,
80  long *minute,
81  long *second,
82  long *msec);
83 
84  class Tracer;
85  class TimeInterpolator;
86  struct Position
87  {
88  float c0;
89  float c1;
90  float c2;
91  };
92 
93 
94 
95 
96 
103  class Kameleon
104  {
105  public:
106  Kameleon();
107  virtual ~Kameleon();
108  long close();
110  bool doesAttributeExist(const std::string& attribute);
111  bool doesVariableExist(const std::string& variable);
112  float getConversionFactorToSI(const std::string& variable);
113  const std::string& getCurrentFilename();
116  Attribute getGlobalAttribute(const std::string& attribute);
117  std::string getGlobalAttributeName(long attribute_id);
118  std::vector<std::string> getLoadedVariables();
119  float getMissingValue();
120  const std::string& getModelName();
121  std::string getNativeUnit(const std::string& variable);
124  int getNumberOfVariables();
125  std::string getSIUnit(const std::string& variable);
126  std::vector<float>* getVariable(const std::string& variable);
127  Attribute getVariableAttribute(const std::string& variable, const std::string& attribute);
128  std::string getVariableAttributeName(long attribute_id);
129  const std::vector<float>* const getVariableFromMap(const std::string& variable);
130  long getVariableID(const std::string& variable);
131  std::vector<int>* getVariableInt(const std::string& variable);
132  const std::vector<int>* const getVariableIntFromMap(const std::string& variable);
133  std::string getVariableName(long variable_id);
134  std::string getVisUnit(const std::string& variable);
135  bool loadVariable(const std::string& variable);
136  bool loadVectorVariable(const std::string& variable);
137  long open(const std::string& filename); //the individual models need a different open method
138  void setMissingValue(float missingValue);
139  bool unloadVariable(const std::string& variable);
140  bool unloadVectorVariable(const std::string& variable);
141  int getProgress();
142  static int _cxform(const char *from,const char *to,const double et,Position* v_in,Position* v_out);
143  static long _cxRound(double doub);
144  static long _date2es(int yyyy, int mm, int dd, int hh, int mm2, int ss);
145  static double _gregorian_calendar_to_jd(int y, int m, int d, int h, int mi, int s);
146 
148 
149  private:
150 
151  boost::unordered_map<std::string, std::string> variableNativeUnits;
152  boost::unordered_map<std::string, std::string> variableSIUnits;
153  boost::unordered_map<std::string, std::string> variableVisUnits;
154 
155  boost::unordered_map<std::string, float> conversionFactorsToSI;
156 
157 
158  boost::unordered_map<std::string, std::string> variableAliases;
159  boost::unordered_map<std::string, std::vector<std::string> > listOfRequiredVariablesForComponents;
160  boost::unordered_map<std::string, std::vector<long> > listOfRequiredVariablesForComponentsByID;
161  boost::unordered_map<std::string, std::vector<std::string> > listOfRequiredVariablesForVectors;
162  boost::unordered_map<std::string, std::vector<long> > listOfRequiredVariablesForVectorsByID;
163 
164 
165  void clearMaps();
166  void initializeUnits();
167  void initializeSIUnits();
168  void initializeVisUnits();
169 
170  void initializeListOfRequiredVariablesForComponentsAndVectors();
171  void initializeExtraInformation();
172 
173  void initializeVariableAliases();
174  void initializeVariableUnits();
175 
176 
177  std::vector<std::string> createVectorOfStringFromList(int num, std::string * strings);
178  std::vector<long> createVectorOfLongFromList(int num, std::string * strings);
179  std::string padString(const std::string& s, int minLength);
180  std::string modelName;
181 
182  std::vector<std::string> getListOfRequiredVariablesForComponents(std::string variable);
183  std::vector<std::string> getListOfRequiredVariablesForVectors(std::string variable);
184 
185  void initializeConversionFactorsToSI();
186  //void initializeConversionFactorsToVis();
187  float missingValue;
188 
189  void addRequirementsForComponents(std::string variable, int num, std::string * variables);
190  void addRequirementsForVectors(std::string variable, int num, std::string * variables);
191 
192 
193 
194 
195  };
196  static boost::unordered_map<int, ccmc::Kameleon *> kameleonObjects;
197  static boost::unordered_map<int, ccmc::Tracer *> tracerObjects;
198  static boost::unordered_map<int, ccmc::Interpolator *> interpolatorObjects;
199  static boost::unordered_map<int, ccmc::GeneralFileReader *> generalFileReaderObjects;
200  static boost::unordered_map<int, ccmc::TimeInterpolator *> timeInterpolatorObjects;
201 
202 }
203 
204 #endif